﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoupdateClient.Mgr
{
    using System.Collections;
    public class ActionMgr
    {
        #region Instance

        private static ActionMgr instance { set; get; } = null;

        public static ActionMgr getInstance()
        {
            if (instance == null)
            {
                instance = new ActionMgr();
            }

            return instance;
        }

        #endregion

        private Hashtable actionHashtable { set; get; } = new Hashtable();

        public void addAction(string packetID, Action<AutoUpdate.Model.Packet.Packet> callback)
        {
            if (!actionHashtable.ContainsKey(packetID))
            {
                this.actionHashtable.Add(packetID, callback);
            }
        }

        public Action<AutoUpdate.Model.Packet.Packet> getAction(string packetID)
        {
            Action<AutoUpdate.Model.Packet.Packet> result = null;
            if (this.actionHashtable.ContainsKey(packetID))
            {
                result = this.actionHashtable[packetID] as Action<AutoUpdate.Model.Packet.Packet>;
            }
            return result;
        }

    }
}
